<?php
$fn_strona = "./strona.html";
$fn_users = "./users.txt";

if(!isSet($_GET["user"]) || !isSet($_GET["pass"])){
  die("error\nNieprawidowe wywoanie skryptu.");
}

if(!$fp = @fopen($fn_users, "r")){
  die("error\nBd sewera. Zalogowanie nie jest moliwe.");
}

$user = $_GET["user"];
$pass = $_GET["pass"];

while (!feof($fp)){
  $str = rtrim(fgets($fp));
  $arr = explode(":", $str);
  if(count($arr) != 3)
    continue;
  if($arr[0] == $user){
    if(sha1($arr[1]) == $pass){
      if($arr[2] != ""){
        $fn_strona = $arr[2];
      }
      if(is_readable($fn_strona)){
        @readfile($fn_strona);
        exit;
      }
      else{
        die("error\nStrona nie jest w tej chwili dostpna.");
      }      
    }
    else{
      die("error\nPodane dane s nieprawidowe.");
    }
  }
}
echo "error\nPodane dane s nieprawidowe.";
?>